/**
 * Created by qingteng.wang on 2017/1/9.
 */

+function($){
    $(function(){
        const $map = $('#kh-concatus-map');
        const address = $map.attr('data-address');

        const map = new BMap.Map('kh-concatus-map');
        const myGeo = new BMap.Geocoder();
        const point = new BMap.Point('武汉市');

        map.centerAndZoom(point,16);

        myGeo.getPoint(address,(point) => {
            if(point){
                const marker = new BMap.Marker(point);
                map.centerAndZoom(point,16);
                map.addOverlay(marker);
            }
        });

        map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别



        const navigationControl = new BMap.NavigationControl({
            // 靠左上角位置
            anchor: BMAP_ANCHOR_TOP_LEFT,
            // LARGE类型
            type: BMAP_NAVIGATION_CONTROL_LARGE,
            // 启用显示定位
            enableGeolocation: true
        });
        map.addControl(navigationControl);
        // 添加定位控件
        const geolocationControl = new BMap.GeolocationControl();
        geolocationControl.addEventListener("locationSuccess", function(e) {
            // 定位成功事件
            const address = '';
            // address += e.addressComponent.province;
            // address += e.addressComponent.city;
            // address += e.addressComponent.district;
            // address += e.addressComponent.street;
            // address += e.addressComponent.streetNumber;
            // alert("当前定位地址为：" + address);
        });
        geolocationControl.addEventListener("locationError", function(e) {
            // 定位失败事件
            alert(e.message);
        });
    })
}(jQuery);